﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Maticsoft.DBUtility;

namespace FineUI.Examples
{
    public partial class major_insertAdminInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string user_name = TextBox1.Text.Trim();
            string password = TextBox2.Text.Trim();
            string phone = TextBox3.Text.Trim();
        }
        public void btnInsert_Click(object sender, EventArgs e)
        {
            string user_name = TextBox1.Text.Trim();
            string password = TextBox2.Text.Trim();
            string phone = TextBox3.Text.Trim();

            Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
            DataTable dt = majorinfo.selectAdminNameIsCunZai(user_name);
            //Label1.Text = dt.Rows[0].ItemArray[0].ToString().Trim();
            try
            {
                if (dt.Rows[0].ItemArray[0].ToString().Trim() != "")
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('已存在当前的用户名，请重新添加！');</script>");
                }
            }
            catch
            {
                bool flag = majorinfo.insertAdminInfo(user_name, password, phone);
                if (flag)
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加管理员成功，请返回！');</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加成功，请返回！');</script>");
                }
            }





            //if (dt.Rows[0].ItemArray[0].ToString().Trim() == user_name)
            //{
            //    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('已存在当前的用户名，请重新添加！');</script>");
            //}



            //string connStr = ConfigurationManager.ConnectionStrings["ReportManagementConnectionString"].ConnectionString;
            //SqlConnection conn = new SqlConnection(connStr);
            //conn.Open();

            //string strsql = "select * from Admin where A_Id = '" + user_name + "' ";
            //SqlCommand cmd = new SqlCommand(strsql, conn);
            //DataSet ds = new DataSet();
            //SqlDataAdapter da = new SqlDataAdapter(strsql, conn);
            //da.Fill(ds, "mytable");

            //string result = ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim();
            //try
            //{
            //    if (result == user_name)
            //    {
            //        Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('已存在当前的用户名，请重新添加！');</script>");
            //    }
            //    else
            //    {
            //        Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
            //        bool flag = majorinfo.insertAdminInfo(user_name, password, phone);
            //        if (flag)
            //        {
            //            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加管理员成功，请返回！');</script>");
            //        }
            //        else
            //        {
            //            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('添加成功，请返回！');</script>");
            //        }
            //    }
            //}
            //catch
            //{
            //    Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('出错了，请联系管理员！');</script>");
            //}


        }

    }
}